
var Main = {
	data() {
		return {
			allqaoptions: [{
					value: '选项1',
					label: '全部数据'
				}, {
					value: '选项2',
					label: 'A'
				}, {
					value: '选项3',
					label: 'B'
				}, {
					value: '选项4',
					label: 'C'
				}, {
					value: '选项5',
					label: 'D'
			}],
			allqainfor: '',
			qaquestion: ''
		}

	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app1')


/* 遮罩层 */
var Main = {
	data() {
		return {
			formLabelWidth: "300px",
			formLabelWidtht: "200px",
			qaform: {
				qaquestion: '',
				qaanswer: '',
				texttips: '',
				qaauthor: '',
				qadate: '',
				qaclassity: '',
				qastatue: ''
			},
			allqaclassity:[],
			allqaclassities:[],
			allqaauthor:[],
			allqaauthors:[],
			dialogFormVisible: false,
			cumloading:false,
			qarules: {
				qaquestion: [{
					required: true,
					message: '必填项',
					trigger: 'change'
				}]
			}
		};
	},
	methods: {
		querySearchAsync(queryString, cb) {
			var restaurants = this.restaurants;
			var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

			clearTimeout(this.timeout);
			this.timeout = setTimeout(() => {
				cb(results);
			}, 3000 * Math.random());
		},
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		//新增获取数据
		getNew(){
			var _this=this;
			this.dialogFormVisible=true;
			axios.post("/aftersale/chooseQAOptions",

			).then(function(v) {
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v);
				//获取作者
				_this.allqaauthor= v.data.oneQAauthor.map(item => {
					return { value: item.u_id, label: item.u_name };
				});
				_this.allqaauthors=_this.allqaauthor;
				//获取分类
				_this.allqaclassity= v.data.oneQAclassity.map(item => {
					return { value: item.value, label: item.label };
				});
				_this.allqaclassities=_this.allqaclassity;
			})/* .catch(function() {
				alert("出错了");
			} )*/;
		},
		//加载作者
		qaauthorMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allqaauthor = _this.allqaauthors.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载分类
		qaclassityMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allqaclassity = _this.allqaclassities.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		/*//加载状态
	    qastatueMethod(query) {
		var _this=this;
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.allqastatue = _this.allqastatues.filter(item => {
							return item.label.toLowerCase()
								.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
				} else {
					this.uosign = [];
				}
			},*/
		submitForm(qaform) {
			//alert("添加！");
			var _this=this;
			this.$refs[qaform].validate((valid) => {
				if (valid) {
					//post提交数据
					axios.post("/aftersale/addQA",
						//参数转换
						Qs.stringify(this.qaform, {
							arrayFormat: 'brackets'
						})
						//id:
						//ajax请求成功的回调函数
					).then(function(v) {
						console.log("回调成功，获取了服务器端返回的值v");
						console.log(v);
						  _this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加成功!',
							duration:3000,
							center: true
						});
		           		//延时两秒刷新
		           		setTimeout(function (){
		           			window.location.href = '/aftersale/qa';
		           		}, 2000);
					}).catch(function() {
						//alert("出错了");
						_this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加失败!',
							duration:3000,
							center: true
						});
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
	}
}

var Ctor = Vue.extend(Main)
new Ctor().$mount('#app2')

/* var x=0;
  function checkallnum(){
     x=x+1;
     document.getElementById('count').innerHTML = x;
  } */

/*  表单  */
var Main = {
	data() {
		return {
			formLabelWidth: "300px",
			allqaauthor:[],
			allqaauthors:[],
			allqaclassity:[],
			allqaclassities:[],
			allqastatue:[],
			allqastatues:[],
			qatable:qatables,
			/*qatable: [{
				ID: '20161123',
				question: '给客户寄送资料',
				qaclassity: '',
				qastutes: '正常',
				num: '0'
			}, {
				ID: '20161123',
				question: '给客户寄送资料',
				qaclassity: '',
				qastutes: '正常',
				num: '0'
			}, {
				ID: '20161123',
				question: '给客户寄送资料',
				qaclassity: '',
				qastutes: '正常',
				num: '0'
			}, {
				ID: '20161123',
				question: '给客户寄送资料',
				qaclassity: '',
				qastutes: '正常',
				num: '0'
			}],*/
			/*currentPage1: 5,
			currentPage2: 5,
			currentPage3: 5,
			currentPage4: 4,*/
			pages: pageinfo,
			currentPage4: pageinfo.pageNum,
			multipleSelection: [],
			dialogFormVisible: false,
			cumloading:false,
			dialogDelete:false,
			formLabelWidth: "300px",
			qaform: {
				ID:'',
				qaquestion: '',
				qaanswer: '',
				texttips: '',
				qaauthor: '',
				qadate: '',
				qaclassity: '',
				qastatue: ''
			},
			qarules: {
				qaquestion: [{
					required: true,
					message: '必填项',
					trigger: 'change'
				}]
			}
		}
	},
	methods: {
		handleClick(row) {
			console.log(row);
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		/*handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
		},*/
		handleSizeChange(val) {
			window.location.href = '/aftersale/qa?pageSize=' + val;

		},
		handleCurrentChange(val) {
			window.location.href = '/aftersale/qa?pageNum=' + val;
		},
/*
		querySearchAsync(queryString, cb) {
			var restaurants = this.restaurants;
			var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

			clearTimeout(this.timeout);
			this.timeout = setTimeout(() => {
				cb(results);
			}, 3000 * Math.random());
		},
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},*/
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		
		deletenew(ID){
			this.ID=ID;
			this.dialogDelete=true;
			
		},
		//删除方法
		Delete(){
			var _this=this;
			axios.get("/aftersale/deleteoneQA",
           			//参数转换
           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
           			//ajax请求成功的回调函数
           			{
						params:{
							ID:_this.ID
						}
           			}
          			).then(function(response){					          				
           			console.log("回调成功，获取了服务器端返回的值v");
           			console.log(response.data);					           		
           		_this.restaurants=response.data;
           		//alert("删除成功！");
           		_this.$message({
           			showClose: true,
					type: 'success',
					message: '删除成功!',
					duration:3000,
					center: true
				});
           		//延时两秒刷新
           		setTimeout(function (){
           			window.location.href = '/aftersale/qa';
           		}, 2000);

           	}).catch(function(){
           		//alert("删除失败！");
           		_this.$message({
					type: 'error',
					message: '删除失败!',
					duration:3000,
					center: true
				});
           	});	//这个是数据的初始化
	      },
	      
	    //打开QA遮罩层
		updatehandleClick(row) {
			this.dialogFormVisible = true;
			var _this = this;
			var id= row;
			console.log(_this);
			axios.post("/aftersale/QAOne",
				Qs.stringify( {
			   			'qa_id':row.ID,
				   },{arrayFormat: 'brackets'}) 
				/* //参数转换
				params:{
					complaintId:row.ID
				} */
				//ajax请求成功的回调函数
			).then(function(v) {
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v.data);
				console.log("作者");
				console.log(v.data.oneQAauthor);
				//获取作者
				_this.allqaauthor= v.data.oneQAauthor.map(item => {
					return { value: item.u_id, label: item.u_name };
				});
				_this.allqaauthors=_this.allqaauthor;
				//获取分类
				_this.allqaclassity= v.data.oneQAclassity.map(item => {
					return { value: item.value, label: item.label };
				});
				_this.allqaclassities=_this.allqaclassity;
				//获取状态
				_this.allqastatue= v.data.oneQAtype.map(item => {
					return { value: item.value, label: item.label };
				});
				_this.allqastatues=_this.allqastatue;
				//传值
				console.log(v.data.oneQAInfo);
				_this.qaform.ID=v.data.oneQAInfo.ID;
				_this.qaform.qaquestion=v.data.oneQAInfo.question;
				_this.qaform.qaanswer=v.data.oneQAInfo.answer;
				_this.qaform.texttips=v.data.oneQAInfo.answer;
				_this.qaform.qaauthor=v.data.oneQAInfo.u_id;
				_this.qaform.qadate=v.data.oneQAInfo.qadate;
				_this.qaform.qaclassity=v.data.oneQAInfo.classifyID;
				_this.qaform.qastatue=v.data.oneQAInfo.status;
				
			})/* .catch(function() {
				alert("出错了");
			} )*/;
			this.dialogFormVisible = true;
		},
		/*//修改点击次数
		updateNum(row){
			alert(row);
			console.log(row.ID);
			var _this=this;
			axios.get("/aftersale/updateNum",
           			{
						params:{
							ID:row.ID
						}
           			}
          			).then(function(response){					          				
           			console.log("回调成功，获取了服务器端返回的值v");
           			console.log(response.data);					           		
           		_this.restaurants=response.data;
           		_this.$message({
           			showClose: true,
					type: 'success',
					message: '修改成功!',
					duration:3000,
					center: true
				});
           	}).catch(function(){
           		_this.$message({
					type: 'error',
					message: '修改失败!',
					duration:3000,
					center: true
				});
           	});	//这个是数据的初始化
		},*/
		//加载作者
		qaauthorMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allqaauthor = _this.allqaauthors.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载分类
		qaclassityMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allqaclassity = _this.allqaclassities.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载状态
	    qastatueMethod(query) {
		var _this=this;
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.allqastatue = _this.allqastatues.filter(item => {
							return item.label.toLowerCase()
								.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
				} else {
					this.uosign = [];
				}
			},
			//表单提交修改
			submitForm(qaform) {
				var _this=this;
				this.$refs[qaform].validate((valid) => {
					if (valid) {
						//post提交数据
						axios.post("/aftersale/updateQA",
							//参数转换
							Qs.stringify(this.qaform, {
								arrayFormat: 'brackets'
							})
							//id:
							//ajax请求成功的回调函数
						).then(function(v) {
							console.log("回调成功，获取了服务器端返回的值v");
							console.log(v);
							  _this.$message({
			           			showClose: true,
								type: 'success',
								message: '修改成功!',
								duration:3000,
								center: true
							});
			           		//延时两秒刷新
			           		setTimeout(function (){
			           			window.location.href = '/aftersale/qa';
			           		}, 1000);
						}).catch(function() {
							//alert("出错了");
							_this.$message({
			           			showClose: true,
								type: 'success',
								message: '修改失败!',
								duration:3000,
								center: true
							});
						});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[qaform].resetFields();
			},
		 downloadfile(){
			window.location.href ="/aftersale/QAExcelDownloads";
		}
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app3')
